﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Streambolics.App
{
    /// <summary>
    ///     The history of a module recovery attempt
    /// </summary>

    public class ModuleRecoveryAttempt
    {
        private int _TotalAttempts;
        private DateTime _FirstAttempted;
        private DateTime _LastAttempted;
        private ModuleRecoveryStrategy _Strategy;

        internal ModuleRecoveryAttempt (ModuleRecoveryStrategy aStrategy)
        {
            _Strategy = aStrategy;
            _TotalAttempts = 1;
            _FirstAttempted = DateTime.Now;
            _LastAttempted = DateTime.Now;
        }

        internal bool MayForget ()
        {
            return _Strategy.RecoveryDelay.ElapsedSince(_LastAttempted);
        }

        /// <summary>
        ///     The total number of times the recovery has been attempted.
        /// </summary>

        public int TotalAttempts
        {
            get
            {
                return _TotalAttempts;
            }
        }

        public DateTime FirstAttempted
        {
            get
            {
                return _FirstAttempted;
            }
        }

        public DateTime LastAttempted
        {
            get
            {
                return _LastAttempted;
            }
        }


        internal void RecordNextAttempt ()
        {
            _LastAttempted = DateTime.Now;
            _TotalAttempts++;
        }
    }
}
